import sys
import time
import decimal
sys.path.append("./modules/")
from BayesNetwork import BayesNetwork

BN = BayesNetwork()
BN.showTime = False
BN.parse("/Users/roosevelt/Desktop/bayes/trunk/data/ini_structures/insurance_ini_structure_lc4.eg")
bn = BN.BayesianNetwork

variables, data = BN.loadDataset("/Users/roosevelt/Desktop/bayes/trunk/data/dataset/insurance_1000_perc30_missing_data.txt")

#BN.expectationMaximization(variables, data, decimal.Decimal('0.01'), bn, param_ini=None, max_iter=3, local=[])
#result = BN.DAHVI(variables, data, 'aic', 'SocioEcon', decimal.Decimal('0.5'), bn)[0]
#BN.printBN(result)

BN.MB_recursive('SocioEcon', [], bn)

#BN.forwardSampling(1, "./out10.txt", decimal.Decimal("0.1"), type="verbose")

#BN.printCPD(BN.variableEliminationInference([('Disconnect', 'True')], [('ErrLowOutput', 'False'), ('HR', 'Normal')], bn))
#print BN.conditionalLogLikelihood(variables, data[1:10], "LLIW", bn)

# # Bayes ball results for the examples in the dissertation
# for example in data:
#     evidence = []
#     for variable, value in zip(variables, example):
#         if value.strip()!="":
#             evidence.append(variable)
#     if "A" in evidence:
#         evidence.remove("A")
#     print BN.bayesBall("A", evidence, bn)[3]
#     
# 
# for example in data:
#     print BN.classifyExample(variables, example, "A", bn)


#score_cache =  {'Coma': decimal.Decimal('-294.6437011'), 'MetastaticCancer': decimal.Decimal('-498.7929857'), 'SerumCalcium': decimal.Decimal('-533.4503447'), 'BrainTumor': decimal.Decimal('-253.9951020'), 'SevereHeadaches': decimal.Decimal('-10000.6808624')}

#print "started"
#st = time.time()
#BN.logLikelihoodDecomposable(variables, data, None, bn, [])
#print time.time() - st
#print BN.localLogLikelihood(variables, data, "Coma", bn)
#st = time.time()
#print BN.logLikelihood(variables, data, bn)
#print time.time() - st

#BN.printBN(bn)
# 
#  
#BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [('D', 'yes'), ('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [('D', 'yes'), ('E', 'no')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [('D', 'no'), ('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [('D', 'no'), ('E', 'no')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'yes'), ('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'yes'), ('E', 'no')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'no'), ('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'no'), ('E', 'no')], bn))
# 
# print ""
# 
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [ ('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [ ('E', 'no')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('E', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('E', 'no')], bn))
# 
# print ""
# 
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [ ('D', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [ ('D', 'no')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'yes')], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [('D', 'no')], bn))
# 
# 
# print ""
# BN.printCPD(BN.variableEliminationInference([('B', 'yes')], [], bn))
# BN.printCPD(BN.variableEliminationInference([('B', 'no')], [], bn))

# BN.printCPD(CPD)
# variables, data = BN.loadDataset("./data/dataset/child_500_perc30_missing_data_trainingset.txt")
# BN.showProgress = False
# BN.showTime = False
# st = time.time()

# print "Started"
# print BN.conditionalLogLikelihood(variables, data, "CO2", BN.BayesianNetwork)
# print BN.countCorrectClassifications(variables, data, "CO2", 0.7, BN.BayesianNetwork)
# bn2 = BN.laplaceSmoothBNParams(BN.BayesianNetwork, decimal.Decimal("0.05"))
# print BN.conditionalLogLikelihood(variables, data, "CO2", bn2)
# print BN.countCorrectClassifications(variables, data, "CO2", 0.7, bn2)
# bn = BN.copy(BN.BayesianNetwork)
# BN.BayesianNetwork = None
# involved_nodes = BN.BBSL_PhaseI(variables, data, "CO2", decimal.Decimal("0.7"), decimal.Decimal("0.1"), bn)
# print involved_nodes
# ESS, new_bn = BN.expectationMaximization(variables, data, decimal.Decimal("0.01"), bn, None, 3, local=list(involved_nodes))
# BN.export_encog("/home/roosevelt/Desktop/bayes/trunk/experiments/BBSL/bbsl_child_500_perc30_net1/0/alarm_final_structure2.eg", new_bn)
# vars = BN.BayesianNetwork.keys()
# print BN.logLikelihood(variables, data, BN.BayesianNetwork)
# print BN.AIC(variables, data, BN.BayesianNetwork, "cll", "CO2")
# bn = BN.generateStructureWithoutEdges(vars)
# for var in vars:
#     bn = BN.addEdge(var, "CO2", bn)
# bn = BN.randomParameterBNInitialization(bn)
# 
# 
# ESS, bn = BN.expectationMaximization(variables, data, decimal.Decimal("0.01"), bn, None, 3, [])
# bn = BN.laplaceSmoothBNParams(bn, decimal.Decimal("0.01"))
# 
# BN.generateBNStructureVisualization("/home/roosevelt/Desktop/view_m", bn)
# 
# print "Training"
# BN.compareBNStructures(bn, BN.BayesianNetwork, variables, data, "CO2", decimal.Decimal("0.07"))
# 
# print "Test"
# variables, data = BN.loadDataset("./data/dataset/child_500_perc30_missing_data_testset.txt")
# BN.compareBNStructures(bn, BN.BayesianNetwork, variables, data, "CO2", decimal.Decimal("0.07"))




# st = time.time()
# CPD = BN.variableEliminationInference([ ('BP', 'Normal')], [('Disconnect', 'False')])
# print time.time() -st
# print CPD

# bn = BN.BayesianNetwork
# variables, data = BN.loadDataset("./data/dataset/cancer_500_missing_data.txt")
# ESS_all, comb = BN.computeAllESS(variables, data, bn, None, False, [])
#
# parents = BN.k2(variables, data, bn.keys(), ESS_all, 1, bn)





# from statsmodels.regression.linear_model import OLS
# import pandas
#
# data = pandas.read_csv("./data/dataset/cancer_4_complete_data.txt")
# model = 'C(MetastaticCancer) ~ C(Coma) + C(SerumCalcium) + C(BrainTumor) + C(SevereHeadaches)'
# results = OLS.from_formula(model, data).fit()
# print results.summary()



# bn = BN.generateStructureWithoutEdges(BN.BayesianNetwork.keys())
# bn = BN.generateStructureWithoutEdges(variables)
# bn = BN.fixedParameterBNInitialization(decimal.Decimal("0.5"), bn)
# ESS_all, combinations = BN.computeAllESS(variables, data, bn)

# query_var = "Coma"
# Test markovBlanketFromData
# blanket = BN.markovBlanketFromData(ESS_all, query_var, bn, min_pvalue=decimal.Decimal("0.05"))
# print blanket

# blankets = BN.computeAllMarkovBlankets(ESS_all, bn, min_pvalue=decimal.Decimal("0.05"))


# bn_not_used, direct_neighbours = BN.computeStructureFromBlankets(blankets, bn, ESS_all, decimal.Decimal("0.05"))


# bn = BN.orientEdgesGS(ESS_all, blankets, direct_neighbours, bn, min_pvalue=decimal.Decimal("0.05"))

# BN.generateBNStructureVisualization("viz0", bn)
# bn, r_set = BN.removeCyclesGS(bn)
#
# BN.generateBNStructureVisualization("viz1", bn)
# bn = BN.reverseEdgesGS(bn, r_set)
#
# BN.generateBNStructureVisualization("viz2", bn)
# #self.GrowShrink( ESS_all, bn, min_pvalue)
# direct_neighbours={}
# direct_neighbours["BrainTumor"] = ["Coma"]
# direct_neighbours["Coma"] = ["MetastaticCancer"]
# direct_neighbours["MetastaticCancer"] = []
# direct_neighbours["SevereHeadaches"] = []
# direct_neighbours["SerumCalcium"] = ["MetastaticCancer"] 
# bn  = BN.propagateDirectionsGS(direct_neighbours, bn)
# BN.generateBNStructureVisualization("viz3", bn)


# BN.GrowShrink(ESS_all, bn)
























# BN.forwardSampling(500, "alarm_500_missing_data.txt", 0.01)


# variables, data = BN.loadDataset("./alarm_missing_data.txt")
# variables = BN.BayesianNetwork.keys()
#
# initial_structure = BN.generateStructureWithoutEdges(variables)
# initial_structure = BN.randomParameterBNInitialization(initial_structure)


# bn = BN.generateRandomStructure(variables, decimal.Decimal('0.1'), max_parents=4)
#
# BN.generateBNStructureVisualization("alarm_ini_structure_viz", bn)
# bn = BN.randomParameterBNInitialization(bn)
# BN.export_encog("alarm_ini_structure_zero", initial_structure)
# bn = BN.randomParameterBNInitialization(bn)
# BN.BayesianNetwork = None
# BN.showTime=False
# ESS_all, comb = BN.computeAllESS(variables, data, bn, None)
# BN.MMHC(variables, data, ESS_all, bn)











# BN.parse_encog("./experiments/bug/log_ini_structure(problem-shorter).eg")
# bn1 = BN.BayesianNetwork

# BN.parse_encog("./data/EncogBayesData/alarm.eg")
# BN.parse_encog("./experiments/log_ini_structure2.eg")
# bn2 = BN.BayesianNetwork
#
# BN.compareBNStructures(bn1, bn2)


# variables, data = BN.loadDataset("./experiments/alarm_verbose.csv")
# BN.nFoldCrossValidation(10, variables, data, './experiments/experiments.py')
# CPD = BN.variableEliminationInference([('Coma', 'Present')])
# print CPD

# BN.forwardSampling(1000, "alarm_missing_data.txt", 0.01)
# bn = BN.BayesianNetwork
#
# factorA = bn.VentLung.CPD
# print len(factorA)
# factorB = bn.VentTube.CPD
# print len(factorB)
# factorC = bn.Press.CPD
# print len(factorC)
#
# CPD_set = [factorA, factorB, factorC]
# CPD_set = BN.eliminateVariable('VentTube',CPD_set)
#
# print len(CPD_set)
# print len(CPD_set[0])
# for CPD in CPD_set:
#    BN.printCPD(CPD)

# join = bn[bn.keys()[0]].CPD
# for i in range(1,len(bn.keys())):
#    join  = BN.joinFactors(join, bn[bn.keys()[i]].CPD)
# BN.printCPD(join)


# query = []
# k = 0
# for node in bn:
#    example = (node, bn[node].Values[1])
#    if (k < 4) and (node!="HR"):
#        query.append(example)
#        k+=1
#
# print query
# st = time.time()    
# CPD = BN.variableEliminationInference(query, [])
# end = time.time() - st
# print end

# BN.printCPD(CPD)

# BN.printBN()



# BN.printBN();
# BN.generateNetNeighbours(nodes_to_consider=['BrainTumor', 'Coma'], external_edges_to_all=['BrainTumor']);
# BN.export_encog("test", BN.BayesianNetwork)
# BN.parse_encog("./test")
# BN.printBN(BN.BayesianNetwork)
# BN.generateBNStructureVisualization('alarm.png', BN.BayesianNetwork

# BN.parse_encog("./data/EncogBayesData/cancer_no_param.eg")
# BN.printBN()
# print str(BN.getProb( ('BrainTumor', False) , [('MetastaticCancer', False)] ))
# newCPD = BN.joinFactors("BrainTumor", "Coma")
# newCPD = BN.summout(newCPD, "BrainTumor")

# CPD = BN.variableEliminationInference('SevereHeadaches', [('Coma','Present'),('SerumCalcium','Increased'),('MetastaticCancer','Present')])
# CPD = BN.variableEliminationInference([('SevereHeadaches', 'Present')], [('Coma','Present'),('SerumCalcium','Increased'),('MetastaticCancer','Present')])
# CPD = BN.variableEliminationInference([('Coma', 'Absent')])
# CPD = BN.variableEliminationInference([('BrainTumor', 'Present'), ('SerumCalcium', 'Increased'), ('Coma', 'Present')], [('Coma', 'Absent'), ('MetastaticCancer', 'Absent'), ('SerumCalcium', 'NotIncreased'), ('BrainTumor', 'Absent'), ('SevereHeadaches', 'Absent')])
# CPD = BN.variableEliminationInference([('Coma', BN.any_value), ('BrainTumor', BN.any_value)], [('BrainTumor', 'Absent'), ('SerumCalcium', 'Increased'), ('MetastaticCancer', 'Absent')])
# CPD = BN.variableEliminationInference([('Disconnect', 'False'), ('ErrLowOutput', 'False'), ('LVFailure', 'False'), ('KinkedTube', 'False'), ('Intubation', 'Normal'), ('MinVolSet', 'Normal'), ('FiO2', 'Normal'), ('Hypovolemia', 'True'), ('InsuffAnesth', 'False'), ('PulmEmbolus', 'False'), ('Anaphylaxis', 'False'), ('ErrCauter', 'True'), ('VentTube', 'Normal'), ('HRBP', 'Low'), ('LVEDVolume', 'Low'), ('StrokeVolume', 'Low'), ('History', 'False'), ('Press', 'Normal'), ('MinVol', 'Normal'), ('VentAlv', 'Normal'), ('Shunt', 'Normal'), ('VentMach', 'Normal'), ('PVSat', 'Normal'), ('Catechol', 'Normal'), ('PAP', 'Normal'), ('TPR', 'High'), ('HREKG', 'Normal'), ('HRSat', 'High'), ('CVP', 'Low'), ('PCWP', 'Low'), ('CO', 'Low'), ('ExpCO2', 'Low'), ('ArtCO2', 'Normal'), ('SaO2', 'Normal'), ('HR', 'Normal'), ('BP', 'High'), ('VentLung', 'Normal'),], [])
# CPD = BN.variableEliminationInference([('Coma', 'Present'), ('MetastaticCancer', 'Absent'), ('SerumCalcium', 'NotIncreased'), ('BrainTumor', 'Present'), ('SevereHeadaches', 'Absent')], [('Coma', 'Present'), ('MetastaticCancer', 'Absent'), ('SerumCalcium', 'NotIncreased'), ('BrainTumor', 'Present'), ('SevereHeadaches', 'Present')])
# BN.printCPD(CPD)

# print "=============================================================="
# BN.gibbsSampler(['BrainTumor', 'Coma', 'SerumCalcium'], ['Absent', 'Absent', 'Increased'], 10)
# CPD = BN.gibbsSamplingInference([('SevereHeadaches', 'Absent')], [('Coma','Present'),('SerumCalcium','Increased'),('MetastaticCancer','Present')])
# CPD = BN.gibbsSamplingInference([('Coma', 'Absent')], [('BrainTumor','Absent'),('SerumCalcium','Increased')])
# BN.printCPD(CPD)

# BN.generateDatasetFromBN(10000, "alarm_complete_data.txt")
# BN.generateDatasetFromBN(10000, "asia_missing_data.txt", {'Cancer': 0.1, 'Tuberculosis': 0.3, 'XRay': 0.2})
# BN.generateDatasetFromBN(10000, "car_missing_data.txt", {'Charge': 0.1, 'Alternator': 0.3, 'FanBelt': 0.2})
# BN.generateDatasetFromBN(10000, "asia_missing_data.txt", {'Cancer': 0.1, 'Tuberculosis': 0.3, 'XRay': 0.2})
# BN.generateDatasetFromBN(10000, "alarm_missing_data.txt", {'Hypovolemia': 0.1, 'StrokeVolume': 0.1, 'CVP': 0.1, 'VentMach':0.1, 'Disconnect':0.1, 'ErrCauter':0.1})
# bn = BN.BayesianNetwork
# join = BN.joinFactors(bn['VentMach'].CPD, bn['Disconnect'].CPD)
#
# BN.printCPD(bn['VentMach'].CPD)
# print ""
# BN.printCPD(bn['Disconnect'].CPD)
# print ""
# BN.printCPD(join)
# print len(bn['VentMach'].CPD)
# print len(bn['Disconnect'].CPD)
# print len(join)

# st = time.time()
# BN.printCPD(BN.generateDataProbabilityTable())
# print time.time() - st
# initial_parameters = ????
# BN.expectationMaximization(initial_parameters, "r_data.txt")

# print BN.loadDataset("r_data.txt")

# CPD = BN.BayesianNetwork.BrainTumor.CPD
# for CPD_line in CPD:
#    print CPD_line
#    print BN.multinomialLikelihood("r_data.txt", CPD_line)
#    break

# variables, data = BN.loadDataset("min_complete_data.txt")
# print "The likelihood is: " + str(BN.logLikelihood(variables, data, None,  False))

# BN.randomParameterBNInitialization()
# bn = BN.BayesianNetwork
# for node in bn:
#    BN.printCPD(bn[node].CPD)
#    print ""

# BN.expectationMaximization("min_missing_data.txt", 0.01)
# start = time.time()
# BN.expectationMaximization("test.txt", 0.01)
# print "time: " + str(time.time() - start)
# print time.time()
# prob_table = BN.generateDataProbabilityTable();
# print time.time()
# for i in range(5000):
# cpd =  BN.inferenceFromProbTable(prob_table, [('Coma','Present'), ('SerumCalcium','Increased')], [('Coma','Present'), ('SerumCalcium','Increased')])
# BN.printCPD(cpd)
# print time.time()
# for i in range(5000):
# cpd  = BN.variableEliminationInference( [ ('SerumCalcium','Increased')], [('Coma','Present'),('MetastaticCancer','Present')])
# print time.time()
# for node in BN.BayesianNetwork:
#    print "node: " + node
#    BN.printCPD(ESS[node])

# print BN.expectedLogLikelihood(variables, data, ESS)

# ESS = BN.computeESS(variables, data)
# for node in BN.BayesianNetwork:
#    print "node: " + node
#    BN.printCPD(ESS[node])

# for node in BN.BayesianNetwork:
 #   self.printCPD(BN.BayesianNetwork[node].CPD)
  #  print ""
# print BN.bayesBall(['Coma'], ['SerumCalcium', 'BrainTumor'])

# BN.mastersAlg("new_data.txt", 0.5)
# BN.removeEdge("BrainTumor", "SevereHeadaches")
# print BN.checkAciclicity()
# combs = BN.generateNetNeighbours()
# print len(combs)
# for comb in combs:
#    print ""
#    print ""
#    print comb
# variables, data = BN.loadDataset("min_complete_data.txt")
# print BN.logLikelihoodCompleteData(variables, data, None)
# print BN.inferenceFromData(variables, data, [('Coma','Present'),('SerumCalcium','*****')] , [] )
# n =  BN.greedyHillClimbing(variables, data)
# variables = BN.BayesianNetwork.keys()
# r_struc = BN.generateRandomStructure(variables)
# bn = BN.greedyHillClimbing(variables, data, r_struc)

# variables, data = BN.loadDataset("min_complete_data.txt")
# variable_arr =[];
# for variable in variables:
#    variable_arr.append(variable)
# BN.generateDataProbabilityTableFromDataFreq(variable_arr, data)

# BN.generateBNStructureVisualization('./bayesian_network.png', bn)
#
# variables, data =  BN.loadDataset("test.txt")
# #print BN.BICScore(variables, data)
# st = time.time()
# comb = BN.generateVariableValuesCombinations(BN.BayesianNetwork.keys())
# print time.time() - st
# combinations = None
# for i in range(10):
#    a = time.time()
#    ESS, comb =  BN.computeESS2(variables, data, comb)
#    print "computeAllESS: " +  str(time.time() - a)
#    print ""
#
#    a = time.time()
#    ESS, combinations =  BN.computeESS(variables, data, combinations)
#    print "computeESS: " +  str(time.time() - a)
#

# SEM
# bn_structure = BN.BayesianNetwork
# BN.generateBNStructureVisualization("original", BN.BayesianNetwork)
# variables, data = BN.loadDataset("alarm_min_missing_data.txt")
# bn_structure = BN.generateRandomStructure(BN.BayesianNetwork.keys(), 0.1)
# bn_structure = BN.randomParameterBNInitialization(bn_structure)
# BN.generateBNStructureVisualization("start", bn_structure)
# BN.structuralExpectationMaximization(variables, data, "example",0.01,"greedyHC", {}, bn_structure)

# EM
# BN.forwardSampling(500, "cancer_min_missing_data.txt", 0.01)
# bn_structure = BN.BayesianNetwork
# variables, data = BN.loadDataset("cancer_min_missing_data.txt")
# bn_structure = BN.generateRandomStructure(BN.BayesianNetwork.keys(), 0.1)
# print "Random structure generated."
# bn_structure = BN.randomParameterBNInitialization(bn_structure)
# print "Random parameters initialized."
# st = time.time()
# print "Starting EM..."
# ESS, bn_structure = BN.expectationMaximization(variables, data, 0.01, bn_structure, None)
# print time.time() - st
# BN.printBN(bn_structure)


# Master Search
# variables, data = BN.loadDataset("min_asia_missing_data.txt")
# bn_structure = BN.BBSL(variables, data, 'Smoking', 0.2, BN.BayesianNetwork)
# BN.generateBNStructureVisualization("BBSL_out", bn_structure)
# BN.compareBNStructures(BN.BayesianNetwork, bn_structure)

# SEM with masters_search
# BN.showProgress = False
# bn_structure = BN.BayesianNetwork
# BN.generateBNStructureVisualization("original", BN.BayesianNetwork)
# variables, data = BN.loadDataset("cancer_min_missing_data.txt")
# bn_structure = BN.generateRandomStructure(BN.BayesianNetwork.keys(), 0.1)
# bn_structure = BN.randomParameterBNInitialization(bn_structure)
# BN.generateBNStructureVisualization("start", bn_structure)
# st = time.time()
# BN.structuralExpectationMaximization(variables, data, "example", 0.01, "BBSL", {'class_variable': 'BrainTumor', 'classification_threshold': 0.7},   bn_structure, 0.5)
# print time.time() - st



# ComputeAllESS
# variables, data = BN.loadDataset("alarm_min_missing_data.txt")
# st = time.time()
# BN.computeAllESS(variables, data,  bn=None, combinations=None,use_prob_table=False)
# print time.time() - st


# Inference from prob table
# evidence = [('Coma', 'Absent'), ('MetastaticCancer', 'Absent')]
# query = [('SerumCalcium', 'NotIncreased'), ('BrainTumor', 'Absent'), ('SevereHeadaches', 'Absent')]
# prob_table = BN.generateDataProbabilityTable()
# cpd = BN.inferenceFromProbTable(prob_table, query, evidence)
# BN.printCPD(cpd)

# Conditional Log Likelihood
# variables, data = BN.loadDataset("missing_data.txt")
# st = time.time()
# cll =BN.conditionalLogLikelihood(variables, data, 'BrainTumor', bn=None)
# print time.time() - st
# print cll


# Mutual Information
# print BN.mutualInformation('VentTube', 'VentLung')


# ExpectedMutualInformation
# variables, data = BN.loadDataset("alarm_super_min_missing_data.txt")
# size =data.shape[0]
# ESS, comb = BN.computeAllESS(variables, data,  None, None,use_prob_table=False)
# st = time.time()
# print BN.expectedMutualInformation('VentTube', 'VentLung', size, ESS, None)
# print time.time() - st

# ComputeAllESS+ComputeESStoBN x ComputeESS comparison
# variables, data = BN.loadDataset("alarm_min_missing_data.txt")
# st = time.time()
# ESS, comb, comb2 = BN.computeESS(variables, data, None, None, False, None)
# print time.time() - st
#
# for node in ESS:
#    BN.printCPD(ESS[node])
#    print ""
#
# print "\n" * 5
# st = time.time()
# ESS, comb, comb2 =  BN.computeESS(variables, data, None, None, True, None)
# print time.time() - st
#
# for node in ESS:
#    BN.printCPD(ESS[node])
#    print ""

# Forward Sampling
# BN.forwardSampling(30, "teste.txt", 0.01)
# BN.forwardSampling(500, "alarm_verbose.csv", 0.01, 'verbose')


# Export to BNT
# BN.export_to_bnt('mk_cancer',  'mk_cancer.m', struct_only=False)
    
# verbose to bnt converter
# BN.verbose2bnt("./experiments/bug/alarm_verbose.csv", "./experiments/bug/to_bnt/alarm_bnt.csv")

